function Ws = Win2Ws(Win,P,T)
% Ws = Win2Ws(Win,T,P) 
% Finds the corresponding inlet deposition rate given an inlet deposition 
% rate. This function can be considered as a simplified gas phase model.

Xin = 0.001;
Win_temp = 5.7423e4*(1.6e4*exp(-18500/T)*(P*Xin))./(1+0.19*sqrt((1-Xin)*P)+0.70*P*Xin);
Win_max = 5.7423e4*(1.6e4*exp(-18500/T)*(P*1))./(1+0.19*sqrt((1-1)*P)+0.70*P*1);
if Win > Win_max
	error('Win should be smaller than %f\n',Win_max);
end
	
while Win_temp < Win
	Xin = Xin+0.001;
	Win_temp = 5.7423e4*(1.6e4*exp(-18500/T)*(P*Xin))./(1+0.19*sqrt((1-Xin)*P)+0.70*P*Xin);
end
if Xin > 0.4377;
	Xin = 0.4377;
end
% For debut only
% W_temp = 5.7423e4*(1.6e4*exp(-18500/T)*(P*Xin))./(1+0.19*sqrt((1-Xin)*P)+0.70*P*Xin)
% fprintf(1,'Recovered W = %f\n',W_temp);
Xs = Xin/0.4377;
Ws = 5.7423e4*(1.6e4*exp(-18500/T)*(P*Xs))./(1+0.19*sqrt((1-Xs)*P)+0.70*P*Xs);